﻿#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.Runtime.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.Office.Client.Policy.dll"

#load "Client.fs"

open Client
open Microsoft.SharePoint.Client
open Microsoft.Office.Client.Policy
open Microsoft.SharePoint.Client.Application
open System.Security;

// =======================================================
// Apply site policy
// =======================================================

let web = Client.Context.Web
Client.Load web


let policy = Microsoft.SharePoint.Client.InformationPolicy.ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(Client.Context, web)
Microsoft.SharePoint.Client.InformationPolicy.ProjectPolicy.GetProjectCloseDate(Client.Context, web)
Client.Load policy

policy

let policies = Microsoft.SharePoint.Client.InformationPolicy.ProjectPolicy.GetProjectPolicies(Client.Context, web)
Client.Load policies

for policy in policies do
    Client.Load policy
    let msg = policy.Name
    printfn "%s\n" msg

let policyApplied = Microsoft.SharePoint.Client.InformationPolicy.ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(Client.Context, web)
Client.ExecuteQuery()
Client.Load policyApplied